<?php

    class IndexController extends Zend_Controller_Action{

        private $_view = null;
        private $_config= null;
        public  $_session= null;

        public function init() {
            /* Initialize action controller here */
            //bezieht viewinstanz
            $this->_view = $this->_helper->layout->getView();

            //Config aus der application.ini auslesen
            $bootstrap = $this->getInvokeArg('bootstrap');
            $config = $bootstrap->getOptions();

            $this->_config = $config['appConfig'];

            //SESSION
            $this->_session = new Zend_Session_Namespace('oncut');
        }

        /**
         *
        */
        public function indexAction(){

            $dbCat   = new Model_DbTables_Vid_Category();
            $dbVideo = new Model_DbTables_Vid_Video();

            $this->view->catResult = $dbCat->getAll();

            $firstCatId = $this->view->catResult[0]['vid_category_nid'];

            if($this->_getParam("catId")){
                $this->view->metaData    = $dbCat->getByNid($this->_getParam("catId"));
                $this->view->videoResult = $dbVideo->getByCatNid($this->_getParam("catId"));
                $this->_session->catId   = $this->_getParam("catId");
            }else{
                $this->view->metaData    = $dbCat->getByNid($firstCatId);
                $this->view->videoResult = $dbVideo->getByCatNid($firstCatId);
                $this->_session->catId   = $firstCatId;
            }

            //ProjectListe laden aus der Session
            $this->view->videoResultProjectList = $dbVideo->getProjectListVideos();

            if(!$this->view->videoResultProjectList){
                $this->view->videoResultProjectList = array();
            }

            //Pfad zum den Video Kategorien Bildern
            $this->view->videoCatImagePath = $this->_config['videoCatImagePath'];
            $this->view->frontendVideoPath = $this->_config['frontendVideoPath'];

            //current ID for highlight
            $this->view->catId = $this->_session->catId;

            //Unterscheidung welcher Div (Liste o. Player) angezeigt wird
            if(Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName() == 'cutplay'){
                $this->view->listDisplay   = "none";
                $this->view->playerDisplay = "block";
            }else{
                $this->view->listDisplay   = "block";
                $this->view->playerDisplay = "none";
            }

        }

        /**
         * Unternehmen Videos anzeigen
         * Unternehmen Navigation erzeugen
         */
        public function companyAction(){
            $dbCompany  = new Model_DbTables_Bus_Company();
            $dbDepart   = new Model_DbTables_Bus_Department();
            $dbImageCat = new Model_DbTables_Images_Category();
            $dbCat   = new Model_DbTables_Vid_Category();


            //$this->view->nav = $dbCompany->getCompanys();

            //Navigation bauen
            $nav = "<ul class='menu'>";
            foreach($dbCompany->getCompanys() AS $com){

                $nav .= '<li class="active">';

                $nav .= "<a href='javascript:void(0);'>";
                $nav .= $com['bus_company_name'];
                $nav .= "</a>";

                $nav .= '<ul class="subMenu">';

                //EVENTS SUBMENU
                $rsDep = $dbDepart->getDepartments($com['bus_company_nid'], 0);
                if(sizeof($rsDep) > 0){

                    $nav .= '<li class="">';
                    $nav .= "<a href='javascript:void(0);'>Events</a>";
                    $nav .= "<ul class='subMenu'>";

                    foreach($rsDep AS $depart){
                        $nav .= '<li class="active"><a href="company?bus_department_nid='.$depart['bus_department_nid'].'">'.$depart['bus_department_name'];
                        $nav .= "</a></li>";
                    }

                    $nav .= "</ul>";
                    $nav .= '</li>';
                }

                //FOOTAG SUBMENU
                $rsDep = $dbDepart->getDepartments($com['bus_company_nid'], 1);
                if(sizeof($rsDep) > 0){

                    $nav .= '<li class="active">';
                    $nav .= "<a href='javascript:void(0);'>Footage</a>";
                    $nav .= "<ul class='subMenu'>";

                    foreach($rsDep AS $depart){
                        $nav .= '<li class="active"><a href="company?bus_department_nid='.$depart['bus_department_nid'].'">'.$depart['bus_department_name'];
                        $nav .= "</a></li>";
                    }

                    $nav .= "</ul>";
                    $nav .= "</li>";
                }

                //Bilderlink nur einzeigen wenn auch Bilder vorhanden sind
                $checkForImages = sizeof($dbImageCat->checkForImages($com['bus_company_nid'], 1));
                if($checkForImages > 0){
                    $nav .= "<li class=''><a href='imagenav?bus_company_nid=".$com['bus_company_nid']."&img_category_nid=".$com['bus_company_nid']."&img_category_pid=0' >Bilder</a></li>";
                }
                $nav .= "</ul>";
            }

            $nav .= "</ul>";

            $this->view->nav = $nav;

            $this->view->catResult = $dbCat->getAllByDepartmentId($this->_getParam('bus_department_nid'), 1);

            //Wasserzeichen Oncut ein ausblenden
            if(sizeof($this->view->catResult) > 0){
                $this->view->watermark = 0;
            }else{
                $this->view->watermark = 1;
            }

        }

        public function cutAction (){
            $this->_helper->viewRenderer->setRender('index');
        }


    }